/**********************************************************************************************/
/* FBL_Algs_Table.cpp																		  */
/*                                                                       					  */
/* Copyright Paradigma, 1993-2006                                        					  */
/* All Rights Reserved.                                                 					  */
/**********************************************************************************************/

#include <VShared/FBL/publ/Headers/StdAfx.h>

#include <VShared/FBL/publ/Algorithms/FBL_Algs_Table.h>

#include <VShared/FBL/publ/Properties/FBL_FieldProperties.h> 


/**********************************************************************************************/
FBL_Begin_Namespace


/**********************************************************************************************/
I_Field_Ptr CreateNumericField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	VALUE_TYPE		inType,
	ushort			inFlags,
	const String& 	inMethod )
{
	I_PropertyContainer_Ptr props;	
	
	//if( inMethod != NULL && *inMethod != 0 )
	if( inMethod.isEmpty() == false )
	{
		props = new PropertyContainer();
		props->Add( new Prop_MethodSql( inMethod ) );
	}
	
	I_Field_Ptr pField = inTable->CreateField( inName, inType, inFlags, props );

	return pField;
}
		

/**********************************************************************************************/
I_Field_Ptr CreateStringField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	ulong			inMaxLength,
	ushort			inFlags,
	const String& 	inMethod )	
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	

	props->Add( new Prop_MaxLen(inMaxLength) );

	if( inMethod.isEmpty() == false )
		props->Add( new Prop_MethodSql( inMethod ) );

	// ---------------
	I_Field_Ptr pField = inTable->CreateField( inName, kTypeString, inFlags, props );
		
	return pField;
}


/**********************************************************************************************/
I_Field_Ptr CreateVarCharField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	ulong			inMaxLength,
	ushort			inFlags,
	const String& 	inMethod )	
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	

	props->Add( new Prop_MaxLen(inMaxLength) );

	if( inMethod.isEmpty() == false )
		props->Add( new Prop_MethodSql( inMethod ) );

	// ---------------
	I_Field_Ptr pField = inTable->CreateField( inName, kTypeVarChar, inFlags, props );
		
	return pField;
}


/**********************************************************************************************/
I_Field_Ptr CreateBLOBField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	ulong			inSegmentSize,
	ushort			inFlags )	
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	
	
	props->Add( new Prop_SegmentSize(inSegmentSize) );

	// ---------------
	I_Field_Ptr	pField = inTable->CreateField( inName, kTypeBLOB, inFlags, props );
		
	return pField;
}


/**********************************************************************************************/
I_Field_Ptr CreateTextField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	ulong			inSegmentSize,
	ushort			inFlags,
	const String& 	inMethod )	
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	
	
	props->Add( new Prop_SegmentSize(inSegmentSize) );

	if( inMethod.isEmpty() == false )
		props->Add( new Prop_MethodSql( inMethod ) );

	// ---------------
	I_Field_Ptr pField = inTable->CreateField( inName, kTypeText, inFlags, props );
		
	return pField;
}


/**********************************************************************************************/
I_Field_Ptr CreatePictureField( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	ulong			inSegmentSize,
	ushort			inFlags )	
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	
	
	props->Add( new Prop_SegmentSize(inSegmentSize) );

	// ---------------
	I_Field_Ptr pField = inTable->CreateField( inName, kTypePicture, inFlags, props );
		
	return pField;
}


/**********************************************************************************************/
I_Field_Ptr CreateObjectPtr( 
	I_Table_Ptr 	inTable, 
	const String& 	inName,
	I_Table_Ptr 	inTarget,
	EOnDeletion		inOnDeletion,
	ushort			inFlags,
	const String& 	inLinkName )
{
	I_PropertyContainer_Ptr props = new PropertyContainer();	
	
	props->Add( new Prop_Target(inTarget) );
	props->Add( new Prop_OnDeletion(inOnDeletion) ); 
	
	if( inLinkName.isEmpty() == false )
		props->Add( new Prop_LinkName( inLinkName ) );

	// ---------------
	I_Field_Ptr pField = inTable->CreateField( inName, kTypeObjectPtr, inFlags, props );
		
	return pField;
}


/**********************************************************************************************/
FBL_End_Namespace
